*Table A.7: Demographic characteristics at baseline Edinburgh and Colchester compared to the English and Scottish Health Surveys
cd ""

*Column 1: England Survey
*HSE 2014
use hse2014ai.dta, clear

*Prepare the 2014 HSE using the experiment selection criteria
*Age
ge age=Age90

*Female
ge female=Sex==2

*Keep if there is a child aged between 2 and 15
keep if Children>0 

*Gen a child indicator of recruitment age i.e. between 2 and 6
egen nchild = total(age>=2 & age<=6), by(hserial)
drop if nchild==0

ge x=1 if (ReltoHRP>=3 & ReltoHRP<=22)
ge ch=(age>=2 & age<=6)
drop if (x==1 & ch==0)

*Keep if below the income threshold
ge inc_included=totinc<14
replace inc_included=. if totinc<0
replace inc_included=. if totinc==.

keep if inc_included==1
*keep if gor1==6

*child benefit
ge child_benefit=srcin11c==1
replace child_benefit=. if srcin11c<0

*child tax credict
ge child_tax_cred=srcin10c==1
replace child_tax_cred=. if srcin10c<0

*Receiving job allowance
ge jsa=srcin05c==1
replace jsa=. if srcin10c<0

*Receiving housing benefits
ge housing_ben=srcin12c==1
replace housing_ben=. if srcin12c<0

*Receiving income support
ge inc_supp=srcin07c==1
replace inc_supp=. if srcin07c<0

*Receiving other benefits
ge other_ben=srcin14c==1
replace other_ben=. if srcin14c<0

*Household Income 
ge hhinc=.
replace hhinc=260 if totinc==1
replace hhinc=790 if totinc==2
replace hhinc=3100 if totinc==4
replace hhinc=4400 if totinc==5
replace hhinc=6500 if totinc==6
replace hhinc=9100 if totinc==7
replace hhinc=11700 if totinc==8
replace hhinc=14300 if totinc==9
replace hhinc=16900 if totinc==10
replace hhinc=19500 if totinc==11
replace hhinc=22100 if totinc==12
replace hhinc=24700 if totinc==13

*higher degree (NVQ4/NVQ5/Degree or equiv)
ge deg=Topqual5==1

*No quals
ge no_qual=Topqual5==4
su female child_benefit child_tax_cred jsa housing_ben inc_supp other_ben hhinc deg no_qual if ch==0
su age if ch==1

*Number of adults in the household
su Adults

*Number of children in the household
bysort hserial: gen Seq=_n
bysort hserial: gen num_ch=_N
keep if Seq==1
su Children


*Column 2: Colcheter experiment
use "demog_adults_edi_essex_shared.dta", clear
joinby id edi  using "sessions_showups.dta", unmatched(both)
drop if _merge==1
ta gender if edi==0 & s1==1

gen age=2015-yearofbirth
su age if edi==0 & s1==1

use "all_demog_clean_10_shared.dta", clear
keep if child==1
gen age=2015-yearofbirth
su age if edi==0 

use "demog_adults_edi_essex_shared.dta", clear
collapse edi nr* h_income_annual_imp , by(hh_id)
su nr_adults_household nr_children_household if edi==0
su h_income_annual_imp if edi==0


use "receiving_benefits_edi_essex_by_hh.dta", clear
su h_earning_child_benefit h_earning_tax_credit h_earning_job_allowance h_earning_housing_benefit h_earning_income_support h_earning_other_benefits if edi==0

use "survey_adults_edi_essex_s134_shared.dta", clear
ge degree_essex=(educational_qualifications==8 | educational_qualifications==9)==1 if edi==0
replace degree_essex=. if educational_qualifications==. & edi==0

ge no_qual_essex=(educational_qualifications==11 | educational_qualifications==13 | educational_qualifications==17)==1 if edi==0
replace no_qual_essex=. if educational_qualifications==. & edi==0

su degree_essex no_qual_essex if edi==0


*Column 3 p-values of tests of the difference
use "demog_adults_edi_essex_shared.dta", clear
joinby id edi  using "sessions_showups.dta", unmatched(both)
drop if _merge==1

**restrict to the ones present at session 1
ta gender if edi==1 & s1==1
ta gender if edi==0 & s1==1
ta gender if  s1==1

gen gender01=1 if gender==2 //female
replace gender01=0 if gender==1 //male

prtest gender01=0.708 if edi==0

gen age=2015-yearofbirth
ttest age=33.5 if edi==0

use "all_demog_clean_10_shared.dta", clear
keep if child==1
gen age=2015-yearofbirth
ttest age=4.0 if edi==0


use "survey_adults_edi_essex_s134_shared.dta", clear
keep if session==1

*keep only one person per hh_id for household level variables
bysort hh_id: gen Seq=_n
ta Seq
keep if Seq==1
count

su nr_adults_household nr_children_household if edi==0

ttest nr_adults_household=1.7 if edi==0
ttest nr_children_household=1.9 if edi==0

use "all_demog_clean_10_shared.dta", clear
collapse edi nr* h_income_annual_imp , by(hh_id)

ttest h_income_annual_imp=15857 if edi==0

use "receiving_benefits_edi_essex_by_hh.dta", clear
prtest h_earning_child_benefit=0.959 if edi==0
prtest h_earning_tax_credit=0.796 if edi==0
prtest h_earning_job_allowance=0.053 if edi==0
prtest h_earning_housing_benefit=0.464 if edi==0
prtest h_earning_income_support=0.179 if edi==0
prtest h_earning_other_benefits=0.075 if edi==0


use "survey_adults_edi_essex_s134_shared.dta", clear
ge degree_essex=(educational_qualifications==8 | educational_qualifications==9)==1 if edi==0
replace degree_essex=. if educational_qualifications==. & edi==0

ta degree_essex if edi==0
prtest degree_essex=0.166 if edi==0

ge no_qual_essex=(educational_qualifications==11 | educational_qualifications==13 | educational_qualifications==17)==1 if edi==0
replace no_qual_essex=. if educational_qualifications==. & edi==0

prtest no_qual_essex=0.226 if edi==0



*Column 4: Scotland (Survey)
*SHS 2014
use shes14i_archive.dta, clear

*Female
ge female=Sex==2

*Gen a child indicator of recruitment age i.e. between 2 and 6
egen nchild0215 = total(age>=2 & age<=15), by(chhserialA)
egen nchild = total(age>=2 & age<=6), by(chhserialA)

ge ch0215=(age>=2 & age<=15)
ge ch=(age>=2 & age<=6)

drop if nchild==0

keep if (age>17 | ch==1)

*Keep if below the income threshold
ge inc_included=totinc<14
replace inc_included=. if totinc<0
replace inc_included=. if totinc==.

keep if inc_included==1


*child benefit
ge child_benefit=SrcInc5==1
replace child_benefit=. if SrcInc5<0

*child tax credict
ge child_tax_cred=SrcInc8==1
replace child_tax_cred=. if SrcInc8<0

*Receiving job allowance
ge jsa=SrcInc6==1
replace jsa=. if SrcInc6<0

*Receiving housing benefits
ge housing_ben=SrcInc9==1
replace housing_ben=. if SrcInc9<0

*Receiving income support
ge inc_supp=SrcInc7==1
replace inc_supp=. if SrcInc7<0

*Receiving other benefits
ge other_ben=SrcInc10==1
replace other_ben=. if SrcInc10<0

ge hhinc=.
replace hhinc=260 if totinc==1
replace hhinc=790 if totinc==2
replace hhinc=3100 if totinc==4
replace hhinc=4400 if totinc==5
replace hhinc=6500 if totinc==6
replace hhinc=9100 if totinc==7
replace hhinc=11700 if totinc==8
replace hhinc=14300 if totinc==9
replace hhinc=16900 if totinc==10
replace hhinc=19500 if totinc==11
replace hhinc=22100 if totinc==12
replace hhinc=24700 if totinc==13

*Degree (NVQ4/NVQ5/Degree or equiv)
ge deg=(TopQua6==1 | TopQua7==1)

*No qual
ge no_qual=TopQua12==1

su female age child_benefit child_tax_cred jsa housing_ben inc_supp other_ben hhinc deg no_qual if ch==0
su age if ch==1

*Number of adults in the household
drop if ch==1
bysort chhserialA: gen Seq=_n
bysort chhserialA: gen adults_hh=_N
keep if Seq==1
su adults_hh

ge ch_hh=HHSize10-adults_hh
su ch_hh


*Column 5 Edinburgh (Experiment)
use "demog_adults_edi_essex_shared.dta", clear
joinby id edi  using "sessions_showups.dta", unmatched(both)
drop if _merge==1
ta gender if edi==1 & s1==1

gen age=2015-yearofbirth
su age if edi==1 & s1==1

use "all_demog_clean_10_shared.dta", clear
keep if child==1
gen age=2015-yearofbirth
su age if edi==1 

use "demog_adults_edi_essex_shared.dta", clear
collapse edi nr* h_income_annual_imp, by(hh_id)
su nr_adults_household nr_children_household if edi==1
su h_income_annual_imp if edi==1


use "receiving_benefits_edi_essex_by_hh.dta", clear
su h_earning_child_benefit h_earning_tax_credit h_earning_job_allowance h_earning_housing_benefit h_earning_income_support h_earning_other_benefits if edi==1


use "survey_adults_edi_essex_s134_shared.dta", clear
ge degree_ed=(educational_qualifications==11 | educational_qualifications==12)==1 if edi==1
replace degree_ed=. if educational_qualifications==. & edi==1

ta degree_ed if edi==1

ge no_qual_ed=educational_qualifications==17 & edi==1
replace no_qual_ed=. if educational_qualifications==. & edi==1

ta no_qual_ed if edi==1



*Column 6 p-values of tests of the difference
use "demog_adults_edi_essex_shared.dta", clear
joinby id edi  using "sessions_showups.dta", unmatched(both)
drop if _merge==1

**restrict to the ones present at session 1
ta gender if edi==1 & s1==1
ta gender if edi==0 & s1==1
ta gender if  s1==1

gen gender01=1 if gender==2 //female
replace gender01=0 if gender==1 //male

prtest gender01=0.664 if edi==1

gen age=2015-yearofbirth
ttest age=33.2 if edi==1

use "all_demog_clean_10_shared.dta", clear
keep if child==1
gen age=2015-yearofbirth
ttest age=3.71 if edi==1


use "survey_adults_edi_essex_s134_shared.dta", clear
keep if session==1

*keep only one person per hh_id for household level variables
bysort hh_id: gen Seq=_n
ta Seq
keep if Seq==1
count

su nr_adults_household nr_children_household if edi==0

ttest nr_adults_household=1.54 if edi==1
ttest nr_children_household=1.81 if edi==1

use "all_demog_clean_10_shared.dta", clear
collapse edi nr* h_income_annual_imp , by(hh_id)

ttest h_income_annual_imp=16884 if edi==1

use "receiving_benefits_edi_essex_by_hh.dta", clear
prtest h_earning_child_benefit=0.940 if edi==1
prtest h_earning_tax_credit=0.687 if edi==1
prtest h_earning_job_allowance=0.037 if edi==1
prtest h_earning_housing_benefit=0.366 if edi==1
prtest h_earning_income_support=0.157 if edi==1
prtest h_earning_other_benefits=0.187 if edi==1


use "survey_adults_edi_essex_s134_shared.dta", clear
ge degree_ed=(educational_qualifications==11 | educational_qualifications==12)==1 if edi==1
replace degree_ed=. if educational_qualifications==. & edi==1
prtest degree_ed=0.269 if edi==1

ge no_qual_ed=educational_qualifications==17 & edi==1
replace no_qual_ed=. if educational_qualifications==. & edi==1
prtest no_qual_ed=0.104 if edi==1

